package com.servlet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Timer;
import java.util.TimerTask;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AutoRunServlet extends HttpServlet{

	/**
	 * Constructor of the object.
	 */
	public AutoRunServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
	
	        Timer timer = new Timer();  
	        timer.schedule(new TimerTask() {  
	            public void run() {  
	            	String url="http://localhost:8080/wifi/gate_inspectBounce.action";
	        		System.out.println("发送地址:"+url);
	        		try {
	        			URL u = new URL(url);
	        			HttpURLConnection httpConn = (HttpURLConnection) u.openConnection(); 
	        			httpConn.setRequestMethod("GET"); 
	        			httpConn.setReadTimeout(1000);
	        			new BufferedReader(new InputStreamReader(httpConn.getInputStream(), "utf-8"));
	        			System.out.println("发送地址成功:"+url);
	        		} catch (Exception e) {
	        		}  
	            }  
	        }, 10000);// 设定指定的时间time,此处为10000毫秒  
	    
		
		System.out.println("好好好");
	}

}
